﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace NTTDATA.BEENChina.ResultCertification.Util
{
    public class CharacterChange
    {
        /// 转全角的函数(SBC case)
        ///
        ///任意字符串
        ///全角字符串
        ///
        ///全角空格为12288，半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
        ///
        public static String ToSbc(String input)
        {
            // 半角转全角：
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 32)
                {
                    c[i] = (char)12288;
                    continue;
                }
                if (c[i] < 127)
                    c[i] = (char)(c[i] + 65248);
            }
            return new String(c);
        }

        /**/
        // /
        // / 转半角的函数(DBC case)
        // /
        // /任意字符串
        // /半角字符串
        // /
        // /全角空格为12288，半角空格为32
        // /其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
        // /
        public static String ToDbc(String input)
        {
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }
                if (c[i] > 65280 && c[i] < 65375)
                {
                    if (c[i].Equals('／'))
                    {
                        continue;
                    }
                    else
                    {
                        c[i] = (char)(c[i] - 65248);
                    }
                }
            }
            return new String(c);
        }


        private char GetKana(char input)
        {
            Dictionary<char, char> jaTable = new Dictionary<char, char>()
                                                 {
                                                     {'ア','あ'},{'イ','い'},{'ウ','う'},{'エ','え'},{'オ','お'},{'カ','か'},
                                                     {'キ','き'},{'ク','く'},{'ケ','け'},{'コ','こ'},{'サ','さ'},{'シ','し'},
                                                     {'ス','す'},{'セ','せ'},{'ソ','そ'},{'タ','た'},{'チ','ち'},{'ツ','つ'},
                                                     {'テ','て'},{'ト','と'},{'ナ','な'},{'ニ','に'},{'ヌ','ぬ'},{'ネ','ね'},
                                                     {'ノ','の'},{'ハ','は'},{'ヒ','ひ'},{'フ','ふ'},{'ヘ','へ'},{'ホ','ほ'},
                                                     {'マ','ま'},{'ミ','み'},{'ム','む'},{'メ','め'},{'モ','も'},{'ヤ','や'},
                                                     {'ユ','ゆ'},{'ヨ','よ'},{'ラ','ら'},{'リ','り'},{'ル','る'},{'レ','れ'},
                                                     {'ロ','ろ'},{'ワ','わ'},{'ヲ','を'},{'ン','ん'},{'ッ','っ'},{'ガ','が'},
                                                     {'ギ','ぎ'},{'グ','ぐ'},{'ゲ','げ'},{'ゴ','ご'},{'ザ','ざ'},{'ジ','じ'},
                                                     {'ズ','ず'},{'ゼ','ぜ'},{'ゾ','ぞ'},{'ダ','だ'},{'ヂ','ぢ'},{'ヅ','づ'},
                                                     {'デ','で'},{'ド','ど'},{'バ','ば'},{'ビ','び'},{'ブ','ぶ'},{'ベ','べ'},
                                                     {'ボ','ぼ'},{'パ','ぱ'},{'ピ','ぴ'},{'プ','ぷ'},{'ペ','ぺ'},{'ポ','ぽ'},
                                                     {'ャ','ゃ'},{'ュ','ゅ'},{'ョ','ょ'}};

            char output;

            bool find = jaTable.TryGetValue(input, out output);
            if (!find)
            {
                output = input;
            }

            return output;
        }
    }
}
